package com.general.framework.example.interval;

import java.util.Map;
import java.util.concurrent.*;
 
public class AsyncApiCallByMultipleThread {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        // 创建线程池
        ExecutorService executor = Executors.newFixedThreadPool(5);
        
        // 提交任务并获取Future对象
        Future<String> futureResult = executor.submit(() -> callThirdPartyAPI());
        
        // 关闭线程池
        executor.shutdown();
        
        try {
            // 从Future对象中获取结果（最多等待10秒）
            String result = futureResult.get(10, TimeUnit.SECONDS);
            
            System.out.println("接口调用成功！结果：" + result);
        } catch (TimeoutException e) {
            System.err.println("超时错误！");
        }
    }

    private static String callThirdPartyAPI() {
        // 发起HTTP请求、调用第三方接口等操作...
        Map<String, String> map = SendRequest.sendGet();
        return "接口返回数据"+ map;
    }
}